#!/bin/bash

# TODO run this once in a while
#doxytag -t ../../tags/qt4.tag /usr/share/doc/qt-4.3.2/html/

# exit on error
set -e

MKDIR_OPT="--verbose --parents"
CP_OPT="--verbose --preserve"
RM_OPT="--recursive --force"
MV_OPT="--verbose --force"

# get the date on format: full week day full month day, year
DATE=$(date +"%A %B %d, %Y")

# update the date ;)
sed -i doc/kisa_footer.html -e "s/Last updated on.*/Last updated on ${DATE}<br>/"

# create the API documentation with standard settings
echo "creating API"
doxygen doxyfile

# append the header
cat doc/kisa_header.html > doc/index.html

# and the actual index body
cat doc/kisa_index.html >> doc/index.html

# and the footer
cat doc/kisa_footer.html >> doc/index.html

# copy the custom index page
cp --force --verbose doc/index.html ../docs/html

# finally the kisa icons
cp --force --verbose icons/kisa{16,32}.png ../docs/html

# rename html dir
VERSION=$(grep "^VERSION = " ../kisa.pro | grep --only-matching "[0-9\.].*")

API_DIR="../docs/kisa-${VERSION}.api.html"
if [[ -d $API_DIR ]]; then
  rm $RM_OPT $API_DIR
  mkdir $MKDIR_OPT $API_DIR
else
  mkdir $MKDIR_OPT $API_DIR
fi

mv $MV_OPT ../docs/html $API_DIR

# user manual
echo "$# creating User Manual"

MANUAL_DIR="../docs/kisa-${VERSION}.manual.html"
if [[ -d $MANUAL_DIR ]]; then
  rm $RM_OPT $MANUAL_DIR
  mkdir $MKDIR_OPT $MANUAL_DIR
else
  mkdir $MKDIR_OPT $MANUAL_DIR
fi

cp $CP_OPT doc/user_manual.html $MANUAL_DIR/index.html
cp $CP_OPT images/appearance.png $MANUAL_DIR/
cp $CP_OPT images/application-exit.png $MANUAL_DIR/
cp $CP_OPT images/behavior.png $MANUAL_DIR/
cp $CP_OPT images/change_on_keyboard_layout.png $MANUAL_DIR/
cp $CP_OPT images/configure.png $MANUAL_DIR/
cp $CP_OPT images/copy_to_clipboard.png $MANUAL_DIR/
cp $CP_OPT images/custom_command.png $MANUAL_DIR/
cp $CP_OPT images/dictionaries.png $MANUAL_DIR/
cp $CP_OPT images/extras.png $MANUAL_DIR/
cp $CP_OPT images/favicon.ico $MANUAL_DIR/
cp $CP_OPT images/font_combo_box.png $MANUAL_DIR/
cp $CP_OPT images/general.png $MANUAL_DIR/
cp $CP_OPT images/google.png $MANUAL_DIR/
cp $CP_OPT images/help-about.png $MANUAL_DIR/
cp $CP_OPT images/hyphen_as_punctuation.png $MANUAL_DIR/
cp $CP_OPT images/icon_file_dialog.png $MANUAL_DIR/
cp $CP_OPT images/ignore_list.png $MANUAL_DIR/
cp $CP_OPT images/kisa16.png $MANUAL_DIR/
cp $CP_OPT images/kisa32.png $MANUAL_DIR/
cp $CP_OPT images/kisa_about.png $MANUAL_DIR/
cp $CP_OPT images/kisa_about_qt.png $MANUAL_DIR/
cp $CP_OPT images/kisa_big_font.png $MANUAL_DIR/
cp $CP_OPT images/kisa_context_menu.png $MANUAL_DIR/
cp $CP_OPT images/kisa.ico $MANUAL_DIR/
cp $CP_OPT images/kisa_dictionary_popup.png $MANUAL_DIR/
cp $CP_OPT images/kisa_disabled.png $MANUAL_DIR/
cp $CP_OPT images/kisa_enabled.png $MANUAL_DIR/
cp $CP_OPT images/kisa_start_menu.png $MANUAL_DIR/
cp $CP_OPT images/kisa_suggestion_popup.png $MANUAL_DIR/
cp $CP_OPT images/kisa_widget_button.png $MANUAL_DIR/
cp $CP_OPT images/kisa_widget_no_button.png $MANUAL_DIR/
cp $CP_OPT images/kisa_widget_no_flag.png $MANUAL_DIR/
cp $CP_OPT images/kisa_widget.png $MANUAL_DIR/
cp $CP_OPT images/kwin.png $MANUAL_DIR/
cp $CP_OPT images/list-add.png $MANUAL_DIR/
cp $CP_OPT images/list-remove.png $MANUAL_DIR/
cp $CP_OPT images/qt-logo.png $MANUAL_DIR/
cp $CP_OPT images/preferences-desktop-keyboard.png $MANUAL_DIR/
cp $CP_OPT images/process-stop.png $MANUAL_DIR/
cp $CP_OPT images/replace_in_client.png $MANUAL_DIR/
cp $CP_OPT images/show_button.png $MANUAL_DIR/
cp $CP_OPT images/show_flag.png $MANUAL_DIR/
cp $CP_OPT images/show_popup.png $MANUAL_DIR/
cp $CP_OPT images/show_systray_popup.png $MANUAL_DIR/
cp $CP_OPT images/stay_on_top.png $MANUAL_DIR/
cp $CP_OPT images/system-run.png $MANUAL_DIR/
cp $CP_OPT images/systray_disabled.png $MANUAL_DIR/
cp $CP_OPT images/systray_menu.png $MANUAL_DIR/
cp $CP_OPT images/systray_popup.png $MANUAL_DIR/
cp $CP_OPT images/trash-empty.png $MANUAL_DIR/
cp $CP_OPT doc/kisa.css $MANUAL_DIR/
